package com.ketangpai.admin.controller;

import com.ketangpai.admin.entity.Course;
import com.ketangpai.admin.entity.dto.CourseDTO;
import com.ketangpai.admin.service.CourseService;
import com.ketangpai.admin.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 课程表(Course)表控制层
 *
 * @author makejava
 * @since 2023-06-14 01:00:12
 */
@RestController
@RequestMapping("course")
@Api(tags = "课程")
public class CourseController {
    /**
     * 服务对象
     */
    @Resource
    private CourseService courseService;

    /**
     * 通过主键查询单条数据
     */
    @ApiOperation("根据id查询")
    @GetMapping("/selectById/{id}")
    public JsonResult<?> selectById(@PathVariable Integer id){
        CourseDTO course=courseService.queryById(id);
        System.out.println(id);
        return JsonResult.success(course);
    }

    @ApiOperation("根据课程号查询")
    @GetMapping("/selectByCode/{code}")
    public JsonResult<?> selectByCode(@PathVariable String code){
     Course course=courseService.queryByCode(code);
        return JsonResult.success(course);
    }
    /**
     * 新增数据
     */
    @ApiOperation("添加")
    @PostMapping("/insert")
    public JsonResult<?> insert(Course course ){
        boolean result= courseService.insert(course);
        if (result) {
            return JsonResult.success("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
    public JsonResult<?> delete(@PathVariable Integer id){
        boolean result= courseService.deleteById(id);
        if (result) {
            return JsonResult.success("删除成功");
        }
        return JsonResult.error("删除失败");
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public JsonResult<?> update( Course course){
        boolean result=   courseService.update(course);
        if (result) {
            return JsonResult.success("编辑成功");
        }
        return JsonResult.error("编辑失败");
    }

//    @ApiOperation("测试上传文件")
//    @PostMapping("/upload")
//    public JsonResult<?> upload(@RequestBody MultipartFile file) {
//      String url=  aliOSSUtil.uploadImg(file);
//        return JsonResult.success((Object) url);
//    }

}

